home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / UCRASM25.ARJ / STRSPANL.ASM < prev    next >
Assembly Source File  |  1991-10-12  |  1KB  |  87 lines

  1. StdGrp        group    stdlib,stddata
  2. stddata        segment    para public 'sldata'
  3. stddata        ends
  4. ;
  5. stdlib        segment    para public 'slcode'
  6.         assume    cs:stdgrp
  7. ;
  8. ;
  9. ; strspanl-    Returns the number of characters (from a set) which
  10. ;        precede a string.
  11. ;
  12. ; inputs:
  13. ;
  14. ;    ES:DI-  Points at string to test.
  15. ;    return address- Points at set of characters (zero terminated string).
  16. ;
  17. ; outputs:
  18. ;
  19. ;    CX-    Number of characters in set which are the prefix of
  20. ;        the test string.
  21. ;
  22. ;
  23. ;
  24. ;
  25.         public    sl_strspanl
  26. ;
  27. sl_strspanl    proc    far
  28.         push    bp
  29.         mov    bp, sp
  30.         pushf
  31.         push    es
  32.         push    ds
  33.         push    ax
  34.         push    bx
  35.         push    dx
  36.         push    si
  37.         push    di
  38.         cld
  39. ;
  40. ; Put the pointers into a couple of better locations.
  41. ;
  42.         mov    ax, es
  43.         mov    ds, ax
  44.         mov    si, di
  45.         les    di, 2[bp]
  46. ;
  47.         mov    bx, di            ;Preserve ptr to char set.
  48.         mov    cx, 0ffffh
  49.         mov    al, 0
  50.     repne    scasb                ;Compute length of char set.
  51.         neg    cx
  52.         dec    cx
  53.         dec    cx
  54.         mov    2[bp], di        ;Save new return address
  55.         mov    dx, cx            ;Save for use later.
  56. ;
  57. ; Okay, now we can see how many characters from the set match the prefix
  58. ; characters in the string.
  59. ;
  60. StrLp:        lodsb                ;Get next char in string.
  61.         mov    cx, dx            ;Get length of char set.
  62.         mov    di, bx            ;Get ptr to char set
  63.     repne    scasb                ;See if in set
  64.         jz    StrLp            ;Repeat while in set.
  65. ;
  66.         pop    di
  67.         mov    cx, di
  68.         sub    cx, si
  69.         neg    cx
  70.         dec    cx
  71.         pop    si
  72.         pop    dx
  73.         pop    bx
  74.         pop    ax
  75.         pop    ds
  76.         pop    es
  77.         popf
  78.         pop    bp
  79.         ret
  80. sl_strspanl    endp
  81. ;
  82. ;
  83. ;
  84. ;
  85. stdlib        ends
  86.         end
  87.